package org.scut.smartgeometry.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import org.scut.smartgeometry.act.HomePageAct;
import org.scut.smartgeometry.utils.ConstantsSG;

/**
 * Created by Administrator on 13-6-28.
 */
public class BacPickerDialog extends ColorPickerDialog {

    private HomePageAct homePageAct;

    public BacPickerDialog(Context context, OnColorChangedListener listener, int initialColor, HomePageAct homePageAct) {
        super(context, listener, initialColor);
        this.homePageAct = homePageAct;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setTitle("Pick a Background Color");

        OnColorChangedListener l = new OnColorChangedListener() {
            public void colorChanged(int color) {
                mListener.colorChanged(color);
                homePageAct = null;
                dismiss();
            }
        };
        ColorPickerView colorPickerView = new ColorPickerView(getContext(), l, mInitialColor);

        LinearLayout linearLayout = new LinearLayout(getContext());
        linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        linearLayout.addView(colorPickerView);

        Button btn = new Button(getContext());
        btn.setText("choose from sdcard");
        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );

        linearLayout.addView(btn);

        setContentView(linearLayout);


        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);

                homePageAct.startActivityForResult(intent, ConstantsSG.REQUEST_CODE_FOR_SELECT_BAC);
                homePageAct = null;
                dismiss();;
            }
        });
    }
}
